# -*- coding:utf-8 -*-
from __future__ import division
from dao.MySqlDAL import MySqlDAL
import json
from util import stock_utils
__author__ = 'shudongma.msd(风骐)'


'''
 没有将点击量和类型加入因素
'''

# 返回积极态度的概率
def getDebateMood(strdate):
    sqlUtil = MySqlDAL()
    res = sqlUtil.get_dimensions_rows("select keywords,click_num,type from tb_stock_debate where date='"+strdate+"'")
    mood_res = 0
    record_count = 0
    # res = list(res)
    # total_click = 0
    # for row in res:
    #     total_click += row['click_num']

    stock_mood = {}
    for row in res:
        # mood_res += json.loads(row['keywords'])['mood_type'] * (1+row['click_num']/(1+total_click))
        keywords = json.loads(row['keywords'])
        mood_res += keywords['mood_type']
        record_count += 1
        if len(keywords['stocks']) != 0:
            for stock in keywords['stocks']:
                stock_mood[stock_utils.stocks_head_dict[stock]] = keywords['mood_type']

    return mood_res/record_count,stock_mood

def getNewsMood(strdate):
    sqlUtil = MySqlDAL()
    res = sqlUtil.get_dimensions_rows("select keywords,click_num,type from tb_stock_news where date='"+strdate+"'")
    mood_res = 0
    record_count = 0
    # res = list(res)
    # total_click = 0
    # for row in res:
    #     total_click += row['click_num']

    stock_mood = {}
    for row in res:
        # mood_res += json.loads(row['keywords'])['mood_type'] * (1+row['click_num']/(1+total_click))
        keywords = json.loads(row['keywords'])
        mood_res += keywords['mood_type']
        record_count += 1
        if len(keywords['stocks']) != 0:
            for stock in keywords['stocks']:
                stock_mood[stock_utils.stocks_head_dict[stock]] = keywords['mood_type']

    return mood_res/record_count,stock_mood


# print getDebateMood('2015-10-12')